// pages/my/index.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gender:"",
    username:"",
    userid:'',
    imgUrl:"",
    desc:""
  },
onLoad(){
 var userinfo=wx.getStorageSync('userinfo')
 console.log(userinfo);
    this.setData({
      gender:userinfo.gender,
      username:userinfo.nickName,
      userid:userinfo.openid,
      imgUrl:userinfo.imgUrl,
      desc:userinfo.desc
    })
  },

  changeAvatar: function() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: res => {
        // tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths);
        this.setData({
          imgUrl: tempFilePaths
        })
      }
    })
  },

  jump: function(e) {
    // 跳转到“个人资料修改页”
    wx.navigateTo({
      // 为了避免用户名中的特殊字符破坏字符串结构，使用encodeURIComponent()编码
      url: '/pages/person/my2/index?username=' + encodeURIComponent(this.data.username) + '&userid=' + encodeURIComponent(this.data.userid) + '&gender=' + encodeURIComponent(this.data.gender)+ '&desc=' + encodeURIComponent(this.data.desc)
    })
  },
  tiao:function(){
    wx.request({
      url: 'http://127.0.0.1:9000/user1/updatePerson',
      method:'POST',
      data:{
        imgUrl:this.data.imgUrl,
        nickName:this.data.username,
        gender:this.data.gender,
        openid:this.data.userid,
        desc:this.data.desc
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' 
        // 默认值
      },
      success:(res)=>{
        console.log(5555);
        console.log(res);
        wx.setStorageSync('userinfo', res.data)
        console.log();
      }
    })

    wx.navigateBack()
  }
})